package Year21_Month10.day1031;

public class BinaryTree<E>{

    public static class BTNode{
        BTNode left;
        BTNode right;
        int data;

        public BTNode(int data){
            this.data = data;
        }
    }

    BTNode root;//构造根节点

    //构造二叉树
    public void creatBinaryTree(){
        BTNode node1 = new BTNode(1);
        BTNode node2 = new BTNode(2);
        BTNode node3 = new BTNode(3);
        BTNode node4 = new BTNode(4);
        BTNode node5 = new BTNode(5);
        BTNode node6 = new BTNode(6);
        node1.left = node2;
        node2.left = node3;
        node1.right = node4;
        node4.left = node5;
        node4.right = node6;

        root = node1;
    }
    //前序遍历
    public void  preOrder(BTNode root){
        if(root == null){
            return;
        }
        System.out.print(root.data + " ");
        preOrder(root.left);
        preOrder(root.right);
    }
    public void  preOrder(){
        System.out.println("前序遍历:");
        preOrder(root);
    }
    public static void main(String[] args) {
        BinaryTree bT = new BinaryTree();
        bT.creatBinaryTree();
        bT.preOrder();
    }
}
